package com.xiaoxin.experience.system.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;

/**
 * <配置restTemplate支持发送https请求>
 *
 * @author xiaoxin
 * <p>
 * 配置前提: springboot web项目
 * 所需maven依赖为:
 *
 * <dependency>
 * <groupId>org.apache.httpcomponents</groupId>
 * <artifactId>httpclient</artifactId>
 * <version>4.5.3</version>
 * </dependency>
 */
@Configuration
public class RestTemplateConfig
{
    @Bean
    public RestTemplate httpsRestTemplate() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException
    {

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setRequestFactory(new HttpsClientRequestFactory());
        return restTemplate;
    }
}
